#!/bin/sh

echo 'welcome'

if [ -z $2 ] ; then
echo "use: pathmgr [file] [deviceid] [vpath] [rpath]"
exit 1
fi

start=#custom_path_$2_begin
stop=#custom_path_$2_end

echo $start
echo $stop
echo $3
echo $4

sed -e ":begin;/$start/,/$stop/{/$stop/!{$!{N;b begin};};s/$start.*$stop//;};" $1 >tmpfile

if [ -z $4 ] ; then
:
else
echo "$start" >> tmpfile
echo "Alias $3 \"$4\"" >> tmpfile
echo "<Directory \"$4\">" >> tmpfile
echo "Options Indexes FollowSymLinks" >> tmpfile
echo "AllowOverride None" >> tmpfile
echo "Order allow,deny" >> tmpfile
echo "Allow from all" >> tmpfile
echo "</Directory>" >> tmpfile
echo "$stop" >>tmpfile
fi

mv tmpfile $1

service httpd restart

